package utilities.input.arrangement;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

import static utilities.input.arrangement.FileInit.getAttribute;

/**
 * 保存的mysql相应的配置信息类
 */
public class MySqlInit extends FileInit {
    public static String databaseName;
    public static String name;
    public static String password;
    static {
        File file = new File(FileInit.mysqlFile);
        Scanner in = null;

        try {
            in = new Scanner(file);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }

        init(in);
    }

    /**
     * 在文件中查找对应的属性配置 赋值属性
     * @param in 文件字符输入流
     */
    protected static void init(Scanner in) {
        while (in.hasNextLine()){
            String s = in.nextLine();
            if (!s.isEmpty() && s.charAt(0) != '#'){
                switch (s.substring(0,s.indexOf('='))){
                    case "数据库名字":
                        databaseName = getAttribute(s);
                        break;
                    case "数据库账号":
                        name = getAttribute(s);
                        break;
                    case "数据库密码":
                        password = getAttribute(s);
                        break;
                    default:

                }
            }
        }
    }
}
